#-*- coding: utf8 -*-
from tutor.scripts import *
from tutor.plugins.sympy import *

def dot_prod(u, v):
    return sum(ui * vi for (ui, vi) in zip(u, v))

while True:
    # Entradas
    with display_block('Entradas'):
        funcExpr = x ** 2 + x * y + y ** 2
        func = Lambda(x, y, funcExpr)
        x0, y0 = ponto2d = (randint(-4, 4) / Two, randint(-4, 4) / Two)
        z0 = func(x0, y0)
        ponto = (x0, y0, z0)
        plano = y - x + x0 - y0

    # Resultados auxiliares
    with display_block('Variáveis auxiliares'):
        X = x0 - z0 / (3 * (x0 + y0))
        Y = y0 - z0 / (3 * (x0 + y0))
        X1 = -z0 / (3 * (x0 + y0))
        Y1 = -z0 / (3 * (x0 + y0))
        X2 = ((x0 - y0) * (2 * y0 + x0) - z0) / (3 * (x0 + y0))
        Y2 = ((y0 - x0) * (2 * x0 + y0) - z0) / (3 * (x0 + y0))

    # Resultados
    with display_block('Respostas'):
        correta = (X, Y)
        if correta == (0, 0):
            continue
        dis1 = (X1, Y1)
        dis2 = (X2, Y2)
        dis3 = (oneof(X, X1, X2), oneof(Y, Y1, Y2))
        dis4 = (oneof(X, X1, X2), oneof(Y, Y1, Y2))
        dis5 = (oneof(X, X1, X2), oneof(Y, Y1, Y2))

        if len(set([correta, dis1, dis2, dis3, dis4, dis5])) != 6:
            continue
        break
